这个"十进制整数N转换为对应2进制数"程序怎么修改,C++

来源:百度知道 编辑:UC知道 时间:2024/05/22 15:15:19
原是由两个程序:
10进制转换2进制
#include <iostream>
const int OK=1;
const int ERROR=0;
const int TRUE=1;
const int FALSE=0;
const int INFEASIBLE=-1;
const int OVERFLOW=-2;
const int STACK_INIT_SIZE=100;
const int STACKINCREMENT=10;
using namespace std;
typedef int Status;
typedef struct SqStack
{int *base;
int *top;
int stacksize;
}SqStack;

//空栈
Status InitStack (SqStack &S) //构造一个空栈S
{S.base = (int*)malloc(STACK_INIT_SIZE*sizeof(int));
if(!S.base) return (OVERFLOW);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
} //IniStack

//入栈
Status Push(SqStack &S,int e) //若栈不空,则用e返回S的栈顶元素,并返回OK;否则返回ERROR
{if(S.top-S.base>=S.stacksize)
{S.base=(int*) realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int));
if(!S.base)
return(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREME

把该句注释掉,编译可以通过。修改标识符,编译可以通过。做大小写的改动,编译可以通过。VC常有这样莫名的错误,可能是和编译器内math.h中的保留关键字有冲突。
另外,算法没有考虑输入非法的情形。
用其他编译器试试